package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"path"
	"strconv"

	"github.com/PuerkitoBio/goquery"
)

var ServerUrl = "http://gbcinternetenforcement.net"

func GenUrls() []string {
	var urls []string
	max := 15000
	for i := 11212; i <= max; i++ {
		url := ServerUrl + "/16-" + strconv.Itoa(i)
		urls = append(urls, url)
	}
	return urls
}

func ExampleScrape(urls []string) {
	for _, url := range urls {
		doc, err := goquery.NewDocument(url)
		if err != nil {
			log.Fatal(err)
			return
		}
		log.Println(doc)
		doc.Find("a[href$=\"SCHEDULEA-AMENDCOMPLAINT.PDF\"]").Each(func(i int, s *goquery.Selection) {
			pdfUrl, _ := s.Attr("href")
			pdfUrl = ServerUrl + pdfUrl
			//log.Println(pdfUrl)
			//downloadFile(pdfUrl)
		})
	}

}

func downloadFile(url string) {
	res, _ := http.Get(url)
	fileName := path.Base(url)
	log.Println(fileName)
	file, _ := os.Create(fileName)
	io.Copy(file, res.Body)
}
func main() {
	urls := GenUrls()
	fmt.Println(urls)
	ExampleScrape(urls)
}
